$(function(){
	layui.use(["layer","form"],function(){
		var layer=layui.layer;
		var form=layui.form;
		
		form.val('example', {
		    "delFlag": delFlag
		  })
		  
		
		form.on('submit(formDemos)', function(data){
			  var index=layer.load(3, { shade: [0.5] });
			  $.ajax({
	                type: "POST",
	                url: "/user/saveDepart",
	                data: data.field,
	                beforeSend: function(request) {
		   	             request.setRequestHeader("token", getCookie('token'));//添加token
		   	        },
	                success: function (r) {
	                	if(r.code ===0){
	                		parent.layer.msg('保存成功!', {icon: 1, time: 1800});
	                		parent.reload();
	                		parent.layer.close(index);
	                		parent.layer.closeAll("iframe");
	                	}else{
	                		layer.msg('保存失败请重试!', {icon: 1, time: 1800});
	                	}
	                },
	                error: function(event, XMLHttpRequest, ajaxOptions, thrownError){
	                	layer.msg('保存失败请重试'); 
	                	layer.close(index); 
	                	console.log(event);
	                	console.log(XMLHttpRequest);
	                	console.log(ajaxOptions);
	                	console.log(thrownError);
	               	}
	            });
		      return false;
		  });
	})
})
